<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div getTime="20" data-index="2" data-list-name="andy"></div>
    <script>
        var div = document.querySelector('div');
        console.log(div.getAttribute('getTime')); //20

        div.setAttribute('data-time', 10); //设置自定义属性
        console.log(div.getAttribute('data-time')); //10

        //h5新增获取自定义属性的方法(只能获取data开头的)
        //dateset 是一个集合 里面存放了所有以date开头的自定义属性
        console.log(div.dataset); //"index": "2","time": "10"
        console.log(div.dataset.index); //2
        console.log(div.dataset['index']); //2
        //如果自定义属性里面有多个 - 链接的单词,我们获取的时候采取 驼峰命名法
        console.log(div.dataset.listName); //andy
        console.log(div.dataset['listName']); //andy
    </script>
</body>

</html>